﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace AnimaGestionPersonnage.Utilities
{
    public class Character
    {
        public string charName { get; set; }
        public int sex { get; set; }
        public string origin { get; set; }
        public int age { get; set; }
        public int height { get; set; }
        public int weight { get; set; }
        public string eyes { get; set; }
        public string hairs { get; set; }
        public int agi { get; set; }
        public int con { get; set; }
        public int dex { get; set; }
        public int str { get; set; }
        public int intel { get; set; }
        public int per { get; set; }
        public int pow { get; set; }
        public int will { get; set; }
        public int app { get; set; }
        public string race { get; set; }
        public string charClass { get; set; }
        public int nbCreation { get; set; }
        public int nbDisadvantave { get; set; }
        public List<AdvDisadv> advantage { get; set; }
        public List<AdvDisadv> disadvantage { get; set; }
        public int totalTP { get; set; }
        public int TPAvail { get; set; }
        public int naturalBonusAvail { get; set; }
        public List<BasicSkill> basicSkills { get; set; }
        public List<PrimarySkill> primarySkills { get; set; }
        public List<SecondarySkill> secondarySkills { get; set; }
        public Weapon principalWeapon { get; set; }
        public List<CombatModule> combatModule { get; set; }
        public List<GeneralModule> generalModule { get; set; }
        public List<TypicalModule> weaponModule { get; set; }

        public bool isAttBlockDiffValid
        {
            get
            {
                return (Math.Abs(this.primarySkills[this.primarySkills.IndexOf(new PrimarySkill(Utils.ATTACK))].tP / Utils.getSkillCost(new PrimarySkill(Utils.ATTACK)) -
                (this.primarySkills[this.primarySkills.IndexOf(new PrimarySkill(Utils.BLOCK))].tP) / Utils.getSkillCost(new PrimarySkill(Utils.BLOCK))) <= 50);
            }
        }

        public bool isAttDodgeDiffValid
        {
            get
            {
                return (Math.Abs(this.primarySkills[this.primarySkills.IndexOf(new PrimarySkill(Utils.ATTACK))].tP / Utils.getSkillCost(new PrimarySkill(Utils.ATTACK)) -
                (this.primarySkills[this.primarySkills.IndexOf(new PrimarySkill(Utils.DODGE))].tP) / Utils.getSkillCost(new PrimarySkill(Utils.DODGE))) <= 50);
            }
        }

        public bool isBlockAttDiffValid
        {
            get
            {
                return (Math.Abs(this.primarySkills[this.primarySkills.IndexOf(new PrimarySkill(Utils.BLOCK))].tP / Utils.getSkillCost(new PrimarySkill(Utils.BLOCK)) -
                (this.primarySkills[this.primarySkills.IndexOf(new PrimarySkill(Utils.ATTACK))].tP) / Utils.getSkillCost(new PrimarySkill(Utils.ATTACK))) <= 50);
            }
        }

        public bool isDodgeAttDiffValid
        {
            get
            {
                return (Math.Abs(this.primarySkills[this.primarySkills.IndexOf(new PrimarySkill(Utils.DODGE))].tP / Utils.getSkillCost(new PrimarySkill(Utils.DODGE)) -
                    (this.primarySkills[this.primarySkills.IndexOf(new PrimarySkill(Utils.ATTACK))].tP) / Utils.getSkillCost(new PrimarySkill(Utils.ATTACK))) <= 50);
            }
        }

        /// <summary>
        /// Indispensable pour la serialization XML
        /// </summary>
        public Character()
        {
            advantage = new List<AdvDisadv>();
            disadvantage = new List<AdvDisadv>();
            basicSkills = new List<BasicSkill>();
            primarySkills = new List<PrimarySkill>();
            secondarySkills = new List<SecondarySkill>();
            combatModule = new List<CombatModule>();
            generalModule = new List<GeneralModule>();
            weaponModule = new List<TypicalModule>();
            totalTP = 600;
            TPAvail = 600;
            naturalBonusAvail = 1;
            agi = 1;
            con = 1;
            dex = 1;
            str = 1;
            intel = 1;
            per = 1;
            pow = 1;
            will = 1;
            app = 1;
            nbCreation = 3;
            nbDisadvantave = 3;
        }

        /// <summary>
        /// Cree un personnage avec des settings personnalises.
        /// </summary>
        /// <param name="creation">le nombre de pts de creation de base</param>
        /// <param name="desavantage">le nombre de desavantage max</param>
        public Character(int creation, int desavantage)
            : this()
        {
            nbCreation = creation;
            nbDisadvantave = desavantage;

        }

        public override string ToString()
        {
            return this.charName;
        }
    }
}
